﻿using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.TagHelpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WebApplication1.TagHelpers
{

    public class ViewContextTagHelper : TagHelper
    {
        [HtmlAttributeNotBound]
        [ViewContext]
        public ViewContext _viewContext { get; set; }

        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            //var rdata = _viewContext.RouteData;  //路由数据
            //var act = _viewContext.ActionDescriptor; //Action描述
            //var vb = _viewContext.ViewBag; //ViewBag

            StringBuilder sb = new StringBuilder();

            foreach (var key in _viewContext.ViewData.Keys)
            {
                sb.AppendFormat($"<li>{key}-----{_viewContext.ViewData[key]}</li>");
            }

            output.Content.SetHtmlContent(sb.ToString());

            output.PreContent.SetHtmlContent("<ul>");
            output.PostContent.SetHtmlContent("</ul>");

        }
    }
}
